<div class="row-fluid">
    <div class="span12">
        <div>
            <p class="nav-header">Actions</p>
            <ul class="nav nav-tabs">
                <li><a href="<?php echo $this->Html->url('add_opinion/' . $broker['Broker']['id']); ?>">New Opinion</a></li>
            </ul>
        </div>
    </div>
</div>
<?php $paginator = $this->Paginator; ?>
<div class="row-fluid">
    <div class="span12">
        <?php echo $this->element('message'); ?>   
        <div class="page-header">
            <h1><?php echo $broker['Broker']['fullname'] ?>'s opinions</h1>
        </div>
        <table class="table table-bordered table-striped">
        <!-- <table class="datagrid"> -->
            <thead>
                <tr>
                    <th><?php echo $paginator->sort('id', 'ID') ?></th>
                    <th><?php echo $paginator->sort('date', 'Date') ?></th>   
                    <th><?php echo $paginator->sort('stock', 'Stock') ?></th>
                    <th>Opinion</th>
                    <th><?php echo $paginator->sort('result', 'Result') ?></th>
                    <th colspan="2">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach ($rows as $row) {
                    $rd_id = rand(1000000000, 9999999999);
                    $opinion = '';
                    $result = $cl = '';

                    switch ($row['Opinion']['result']) {
                        case 1:
                            $result = 'Right';
                            $cl = 'success';
                            break;
                        case 2:
                            $result = 'Wrong';
                            $cl = 'error';
                            break;
                    }

                    switch ($row['Opinion']['opinion']) {
                        case 0:
                            $opinion = 'Up';
                            break;
                        case 1:
                            $opinion = 'Unchange';
                            break;

                        default:
                            $opinion = 'Down';
                            break;
                    }
                    echo "<tr class='{$cl}'>";
                    echo "<td>{$row['Opinion']['id']}</td>";
                    echo "<td>" . date('Y-m-d', strtotime($row['Opinion']['date'])) . "</td>";
                    echo "<td>{$row['Stock']['name']}</td>";
                    echo "<td>{$opinion}</td>";
                    echo "<td>{$result}</td>";
                    echo "<td>{$this->Html->link(__('Edit'), array('action' => 'edit_opinion', $row['Opinion']['id'], $row['Opinion']['broker']), array('class' => 'btn btn-warning'))}</td>";
                    echo "<td><form action=\"{$this->Html->url('delete_opinion/' . $row['Opinion']['id'] . '/' . $row['Opinion']['broker'])}\" name=\"post_{$rd_id}\" id=\"post_{$rd_id}\" style=\"display:none;\" method=\"post\"><input type=\"hidden\" name=\"_method\" value=\"POST\"></form>{$this->Html->link(__('Delete'), '#', array('class' => 'btn btn-danger', 'onclick' => 'if (confirm( \'Are you sure you want to delete #' . $row["Opinion"]["id"] . '\')) {document.post_' . $rd_id . '.submit(); } event.returnValue = false; return false;'))}</td>";
                    echo "</tr>";
                }
                ?>
            </tbody>
        </table>

        <div class="pagination">
            <ul>
                <?php
                echo '<li>' . $paginator->first("First") . '</li>';
                if ($paginator->hasPrev()) {
                    echo '<li>' . $paginator->prev("Prev") . '</li>';
                }
                // the 'number' page buttons
                echo $paginator->numbers(array('modulus' => 3, 'tag' => 'li', 'separator' => '', 'currentTag' => 'a', 'currentClass' => 'active'));

                // for the 'next' button
                if ($paginator->hasNext()) {
                    echo '<li>' . $paginator->next("Next") . '</li>';
                }
                // the 'last' page button
                echo '<li>' . $paginator->last("Last") . '</li>';
                ?>
            </ul>
        </div>
    </div>
</div>
